/*
Here is an explanation of how to use these procedures:

First, at the beginning of the heap extraction code, before you read the data
from disk, call once:

  base = initCoder();

and store the value base in a global variable or something. You will need it.

Now suppose you have read the postings for one document and computed the
total scores of the postings (static+dynamic part). Suppose that there are
m postings in the document, and that the termids and scores are stored
in termid[] and score[] as follows:

int m;
int termid[m];
double score[m];

Now you store these postings in an array of type unsigned char as follows:

unsigned char *data = (unsigned *) malloc(8 * m * sizeof(unsigned char));
// note that 8*m is always enough space but much less is usually used

int i;
int wptr;     // wptr keeps track of how much many chars were written
for (i = 0, wptr = 0; i < m; i++)
  wptr += codePost(termid[i], score[i], base, data+wptr);

Now the encoded data is in the unsigned char array in data[0 ... wptr-1], so
you can copy those wptr bytes to wherever you want.

Later, suppose you need to read the next (score, termid) pair from the data
for a particular document, in order to put it into the heap.

Initially, when you read the first pair of the doc, set the read pointer rptr

unsigned char *rptr = first byte of data for this document

and then read a new pair into variables int termid and double score by calling

rptr += decodePost(&termid, &score, base, rptr);  // note passing of pointers

until all posts have been read. You need to know when all posts have been
read from document, so keep number of posts of each doc, or use sentinels

Also, you need to store the rptr for each document, so you have it for the
next time you call decodePost() on the same document.
*/

#define MINSC 0.0	// smallest score / probability of any post in collection under static method
#define MAXSC 1.0	// largest score / probability of any post in collection under static method
#define MAXALPHA 100.0	// largest value of alpha you can use


#include <iostream>
#include <math.h>
#include <sstream>
#include <string.h>

using namespace std;

class postingQuantization{
public:
	postingQuantization();
	int codePost(int termid, double score, unsigned char *data);
	int decodePost(int *termid, double *score, unsigned char *data);
	int codePostDummy(int termid, double score, unsigned char *data_buffer_write_ptr,unsigned char *data_buffer_read_ptr);
	int decodePostDummy(int *termid, double *score, unsigned char *data);

private:
	double base_;
	int positionIndexStored_;
	int positionIndexOut_;
};
